Ext.define('DragonApp.view.gift.Controller', {
    extend: 'Ext.app.ViewController',

    alias: 'controller.gift',

    onSubmitClick: function(button, e, options) {

        var me = this;

        var form = this.getView().getForm();

        if (!form.isValid()) return;

        var formValue = form.getValues();

        var panel = Ext.ComponentQuery.query('giftpanel')[0];
        var grid = panel.down('grid');
        var store = grid.getStore();


        grid.mask('查询中...');

        //数据仓库根据查询附加参数加载

        store.load({
            params: formValue,
            scope: this,
            callback: function(records, operation, success) {

                grid.unmask();

                if (success == false) {
                    store.removeAll();
                }
            }
        });
    },

    onTextFieldSpecialKey: function(field, e, options) {
        if (e.getKey() === e.ENTER) {
            if (this.getView().getForm().isValid()) {
                this.onSubmitClick();
            }
        }
    },

    //============
    //内容提示渲染
    //============
    attrRender: function(value, metadata, record, rowIndex, columnIndex, store) {

        if (typeof(value) == "undefined") {
            value = '';
            metadata.tdAttr = 'data-qtip="' + value + '" ' + 'data-qalign="bl-br"' + 'data-qwidth="auto"';
            return value;
        } else {
            metadata.tdAttr = 'data-qtip="' + value + '" ' + 'data-qalign="bl-br"' + 'data-qwidth="auto"';
            return value;
        }
    }
});